<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class c_home extends MY_controller {
	
	function __construct(){
		parent::__construct();
		$this->load->model('m_admin');
		$this->load->model('mdl_general');
		if($this->uri->segment(2) != "logout" && $this->m_admin->isLogin()){
			redirect('home');
		}
	}
	
	public function index()
	{
		$this->load->view('v_home');
	}
    
	public function checklogin()
	{
		$check=$this->m_admin->cekUserPass($this->input->post('username'),$this->input->post('password'));
		if($check){
			$this->session->set_userdata('username', $this->input->post('username'));
			
			$where 	= array('username' => $this->input->post('username'));
			$data	= $this->mdl_general->getWhere($where, 'user', 1);
			
			$this->session->set_userdata('u_kdprov', $data->kd_propinsi);
			$this->session->set_userdata('u_kdkab', $data->kd_kabkota);
			
			redirect('home');
		} else{
			redirect('c_home');
		}
	}

	public function logout()
	{
		$this->session->sess_destroy();
		redirect('c_home');
	}
	
}
?>
